package realizeBockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-04-05
 * Time: 18:13
 */
public class TestMyBlockingQueue {
    public static void main(String[] args) {
        MyBlockingQueue myBlockingQueue = new MyBlockingQueue();
        // 消费者
        Thread t1 = new Thread(()->{
            while (true) {
                try {
                    int value = myBlockingQueue.take();
                    System.out.println("消费元素："+value);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        // 生产者
        Thread t2 = new Thread(()->{
            int value = 0;
            while (true) {
                try {
                    myBlockingQueue.put(value);
                    System.out.println("生产元素："+value);
                    value++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });

        t1.start();
        t2.start();
    }
}
